home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97a.txt / 000008_icon-group-sender _Sat Jan 4 14:27:03 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Mon, 6 Jan 1997 06:20:04 MST
  2. To: icon-group@cs.arizona.edu
  3. Date: 4 Jan 1997 14:27:03 GMT
  4. From: espie@aviso.ens.fr (Marc Espie)
  5. Message-Id: <5alpbn$3kd@nef.ens.fr>
  6. Organization: Ecole Normale Superieure, Paris
  7. Sender: icon-group-request@cs.arizona.edu
  8. References: <32CDB3E4.3358@ohsu.edu>
  9. Subject: Re: Another Question from the Neophyte
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11. Status: RO
  12. Content-Length: 1869
  13.  
  14. In article <32CDB3E4.3358@ohsu.edu>,
  15. Stuart Robinson  <robinstu@ohsu.edu> wrote:
  16.  
  17. >But I've run into a new problem.  I have found numerous options for
  18. >scanning forward in a string, but I haven't found a good way to move
  19. >backwards, besides first reversing a string and then scanning forward
  20. >(which is functionally scanning backwards).
  21.  
  22. >For example, I created the following little program to extract the names
  23. >of some functions nestled at the end of some lines of HTML (see input
  24. >below):
  25. >
  26. >=======================
  27. >procedure main()
  28. >
  29. >while line := reverse(read()) do
  30. >line ?
  31. >
  32. >{
  33. >write(reverse(tab(upto(" "))))
  34.                         ^^^
  35. bad code... upto() takes a cset as an argument. You're suffering an hidden
  36. conversion string->cset here. Use tab(upto(' ')) instead.
  37.  
  38. >cset()
  39. >string()
  40. >find()
  41. >etc.
  42. >
  43. >I did manage to find a solution, but isn't there less cumbersome way of
  44. >scanning backwards than using reverse()?
  45. >
  46. You can write reverse functions to upto and friends. This is rather easy
  47. using &subject and &pos. The most difficult part is to get the generator
  48. part okay. I remember seeing some of Icon's matching functions written in 
  49. Icon in the Icon book.
  50.  
  51. Some function along these lines should work (untested code...caution):
  52.  
  53. procedure downto(c, s, i1, i2)
  54.     /i1 = if /s then &pos else *s
  55.     /s = &subject
  56.     /i2 = 1
  57.     every i := i1 to i2 by -1 do
  58.         if member(c, s[i]) then suspend i
  59. end
  60.  
  61. This might give some performance hit, though. In case this is not 
  62. acceptable, locating the rtl code for upto and writing a reverse function
  63. should be a breeze... even though this is most certainly not suitable for
  64. the Icon main distribution.
  65.  
  66. -- 
  67. [nosave]<http://www.eleves.ens.fr:8080/home/espie/index.html>
  68. microsoft network is EXPLICITLY forbidden to redistribute this message.
  69. `Seiza no matataki kazoe, uranau koi no yuku e.'
  70.     Marc Espie (Marc.Espie@ens.fr)
  71.